LD=g++
LDFLAGS=

VPATH=
CPPGIMI=
CGIMI=

GDIR=../../..
GIMIPATH=$(GDIR)/GIMI
MACIPATH=$(GDIR)/MaCI
GIMBOPATH=$(GDIR)/Gimbo
## Build GIMI and it's dependencies.
## Files are set to CGIMI and CPPGIMI variables
include $(GIMIPATH)/Makefile.gimi

## Include MaCI-stuff
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile
include Makefile.loggers

CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS) $(CE)
CPPFLAGS=$(DEBUG) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS) $(CE)
DCPPFLAGS=$(DEBUG) $(CPPINCLUDES) $(DEFINITIONS) $(CE)
DEBUG=-O0 -g3
CMISCFLAGS=
CPPMISCFLAGS=-Wall -Wunused -Wshadow -Weffc++
DEFINITIONS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES $(CE) 
CINCLUDES=-I. -I../../ -I$(GDIR)/utils $(INCGIMI)
CPPINCLUDES=-I. -I../../ \
		`xml2-config --cflags` \
		`wx-config --cflags --unicode=no` \
		$(MACI_INCLUDE_PATHS) \
 		$(MACI_INTERFACE_IMAGE_EXT_INCLUDE) \
		-I$(GIMBOPATH)/components/MaCI_Logger/loggers \
		$(LOGGERINCLUDES) \
	        $(INCGIMI) -I$(GDIR)/utils


LD=g++
LDFLAGS=-ljpeg
LIBS=-lrt -lpthread `xml2-config --libs` `wx-config --libs std,gl --unicode=no` $(LIBSGIMI)\
	$(MACI_INTERFACE_IMAGE_EXT_LIBS)  `libpng-config --libs` -lssl

## Define GIMBO sources
GIMBOSRCSC= $(MACI_INTERFACE_IMAGE_EXT_C)
GIMBOSRCSCPP=$(GIMBOPATH)/Component.cpp

## Construct final lists of CPP and C objects
OBJSC=$(CGIMI:.c=.o) $(GIMBOSRCSC:.c=.o) $(MACI_INTERFACE_IMAGE_EXT_C:.c=.o)
OBJSCPP=$(CPPGIMI:.cpp=.opp) \
	$(MACI_BASE_SRC_CPP:.cpp=.opp) \
	$(MACI_EXT_SRC_CPP:.cpp=.opp) \
	$(GIMBOSRCSCPP:.cpp=.dopp)\
	$(MACI_INTERFACE_RANGING_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_RANGINGCLIENT_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_POSITION_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_POSITIONCLIENT_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_SPEEDCTRL_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_SPEEDCTRLCLIENT_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_IMU_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_IMUCLIENT_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_ENERGY_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_ENERGYCLIENT_CPP:.cpp=.opp) \
	$(MACI_INTERFACE_WIRELESS_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_WIRELESSCLIENT_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_COORDINATEDRIVE_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_COORDINATEDRIVECLIENT_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_IMAGE_COMMON_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_IMAGECLIENT_CPP:.cpp=.opp)\
	$(MACI_INTERFACE_IMAGE_EXT_CPP:.cpp=.opp)
#LOGGEROBJSCPP=
## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS)  $(CPPINCLUDES) -c
COMPILEDCPP=$(CXX) $(DCPPFLAGS) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

TARGETS=MaCI_Logger 

all: $(TARGETS)

install:	all
	cp -v MaCI_Logger.xml ../

MaCI_Logger: $(OBJSC) $(OBJSCPP) $(LOGGEROBJSCPP) \
	MaCI_Logger.dopp \
	MaCI_Logger_GUI.dopp \
	MaCI_Logger_MainFrame.dopp \
	MaCI_Logger_About_Dialog.dopp \
	MaCI_LoggerQuestion_Dialog.dopp \
	MaCI_Logger_Error_Dialog.dopp \
	LoggerGenerator.opp
	@$(LINK) -o $@ $^
	@echo "      [LD] $@"
	@mkdir -p ./data

#MaCI_Logger_terminal: $(OBJSC) $(OBJSCPP) $(LOGGEROBJSCPP) 
#	@$(COMPILECPP) -DMACI_LOGGER_WITHOUT_WX -o MaCI_Logger.opp MaCI_Logger.cpp
#	@$(COMPILECPP) -DMACI_LOGGER_WITHOUT_WX -o MaCI_Logger_woWX.opp MaCI_Logger_woWX.cpp
#	@$(LINK)  -o $@ $^
#	@echo "      [LD] $@"
#	@mkdir -p ./data
#MACI_LOGGER_WITHOUT_WX
clean:
	@rm -f *.dopp *.opp *.o *~ loggers/*.dopp loggers/*.opp $(TARGETS)
	@echo "      [CLEAN]"

realclean: clean
	@rm -f *.state *.log $(OBJSC) $(OBJSCPP)
	@echo "      [REALCLEAN]"


## Below this is dependency generation stuff, no need to change.
## Compile rule for all .o (.c) file
%.o:    %.c
	$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

## Compile rule for all .opp (.cpp) files
%.opp:  %.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"

# Compile rule for all .dopp (dirty .cpp) files
%.dopp:	%.cpp
	@$(COMPILEDCPP) -o $@ $<
	@echo "      [DIRTY-CXX] $<"

